/*
 * @Author: ZephyrGao
 * @Date: 2024-02-27 08:01:27
 * @Description: 
 * Copyright (c) 2024 by ZephyrGao, All Rights Reserved. 
 */
// test.ts

import { MockMethod } from 'vite-plugin-mock'

const database = {
  userList: [
    {
      id: 1,
      name: 'vben',
      email: 'vben@vben',
      password: '123456',
      roles: ['admin'],
    },
    {
      id: 2,
      name: 'gai',
      email: '312@vben',
      password: '12345622',
    },
    {
      id: 3,
      name: 'gzj',
      email: '312@vben',
      password: '123',
    },
  ],
}

type User = {
  username: string;
  password: string;
};

export default [
  {
    url: '/api/user/login',
    method: 'post',
    response: ( body: { body: User }) => {
      const { username, password } = body.body;
      // console.log(body.User)
      const user = database.userList.find((item) => item.name === username)
      if (user && user.password === password) {
        return {
          code: 200,
          msg: '登录成功',
          data: {
            token: '123456',
          }  
        }
      }
      return {
        code: 500,
        msg: '用户名或密码错误',
      }
   
    },
  }
] as MockMethod[]

